package com.onetech.adrewards.free.activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.google.analytics.tracking.android.EasyTracker;
import com.onetech.adrewards.free.R;
import com.todddavies.components.progressbar.ProgressWheel;

public class CommonWebViewInfoActivity extends BaseActivity {
	private WebView mWebViewContent=null;
	private ProgressWheel mProgress=null;
	/*private View mNotFoundView=null;
	private View mRetryBtn=null;*/
	private String url="http://adreward.onetechonline.com/index.php/v2/page/1";
	private String title="";
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setMainView(R.layout.dialog_common_info_layout);
		
		getUrlIntent();
		setAppTittle(title);
		initView();
		initListener();
	}
	private void getUrlIntent(){
		try {
			Intent intent=this.getIntent();
			url=intent.getExtras().getString("URL");
			title=intent.getExtras().getString("ViewTitle");
		} catch (Exception e) {
			url="http://adreward.onetechonline.com/index.php/v2/page/1";
		}
	}
	private void initView(){
		showFooterView(false);
		showMyPoints(false);
		
		
		
		mWebViewContent=(WebView)findViewById(R.id.webViewContent);
		/*mNotFoundView=(LinearLayout)findViewById(R.id.notFoundDataContainer);
		mRetryBtn=(LinearLayout)findViewById(R.id.btnRetry);
		mRetryBtn.setOnClickListener(this);*/
		
		mProgress=(ProgressWheel)findViewById(R.id.progressWheel);
		mProgress.spin();
		showViews(false, true, false);
		mWebViewContent.loadUrl(url);
		mWebViewContent.setWebViewClient(new WebViewClient(){
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
				showViews(false, true, false);
			}
			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				showViews(false, false, true);
			}
		});
	}
	private void initListener(){
		
	}
//	public CommonWebViewInfoActivity(Context context,String title,String url){
//		super(context, title,
//				TYPE_NO_BUTTON, R.layout.dialog_common_info_layout);
//		mWebViewContent=(WebView)findViewById(R.id.webViewContent);
//		/*mNotFoundView=(LinearLayout)findViewById(R.id.notFoundDataContainer);
//		mRetryBtn=(LinearLayout)findViewById(R.id.btnRetry);
//		mRetryBtn.setOnClickListener(this);*/
//		
//		mProgress=(ProgressWheel)findViewById(R.id.progressWheel);
//		mProgress.spin();
//		showViews(false, true, false);
//		mWebViewContent.loadUrl(url);
//		mWebViewContent.setWebViewClient(new WebViewClient(){
//			@Override
//			public void onPageStarted(WebView view, String url, Bitmap favicon) {
//				super.onPageStarted(view, url, favicon);
//				showViews(false, true, false);
//			}
//			@Override
//			public void onPageFinished(WebView view, String url) {
//				super.onPageFinished(view, url);
//				showViews(false, false, true);
//			}
//		});
//	}	
	private void showViews(boolean notFound,boolean progressBar,boolean webView){
		//mNotFoundView.setVisibility(notFound?View.VISIBLE:View.GONE);
		mProgress.setVisibility(progressBar?View.VISIBLE:View.GONE);
		mWebViewContent.setVisibility(webView?View.VISIBLE:View.GONE);
	}
	@Override
	public void onClick(View v) {
		int id=v.getId();
		switch (id) {
		case R.id.btnRetry:
			mWebViewContent.reload();
			break;
		default:
			super.onClick(v);
			break;
		}
	}
	@Override
	public void onStart() {
	    super.onStart();
	   // The rest of your onStart() code.
	    try {
	    	EasyTracker.getInstance(this).activityStart(this);  // Add this method.
		} catch (Exception e) {			
		}
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    // The rest of your onStop() code.
	    try {
	    	EasyTracker.getInstance(this).activityStop(this);  // Add this method.
		} catch (Exception e) {
		}
	  }
}
